package com.frank.subject.domain.handler.subject;

import com.frank.common.enums.IsDeletedFlagEnum;
import com.frank.subject.common.enums.SubjectInfoTypeEnum;
import com.frank.subject.domain.convert.SubjectBriefBoConverter;
import com.frank.subject.domain.entity.SubjectInfoBo;
import com.frank.subject.domain.entity.SubjectOptionBo;
import com.frank.subject.infra.basic.entity.SubjectBrief;
import com.frank.subject.infra.basic.service.SubjectBriefService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author Frank Zou
 * @version v0.0.1
 * @date 2024/1/25 2:17 PM
 * @description 简答题类型策略类
 */
@Component
public class BriefTypeHandler implements SubjectTypeHandler {

    @Resource
    private SubjectBriefService subjectBriefService;

    @Override
    public SubjectInfoTypeEnum getHandlerType() {
        return SubjectInfoTypeEnum.BRIEF;
    }


    @Override
    public void add(SubjectInfoBo subjectInfoBO) {
        SubjectBrief subjectBrief = SubjectBriefBoConverter.INSTANCE.convertBoToEntity(subjectInfoBO);
        subjectBrief.setSubjectId(subjectInfoBO.getId());
        subjectBrief.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
        subjectBriefService.save(subjectBrief);
    }

    @Override
    public SubjectOptionBo query(Long subjectId) {
        SubjectBrief subjectBrief = subjectBriefService.queryBySubjectId(subjectId);
        SubjectOptionBo optionBo = new SubjectOptionBo();
        optionBo.setSubjectAnswer(subjectBrief.getSubjectAnswer());
        return optionBo;
    }
}
